// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IRollingArray.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.Interfaces
{
    /// <summary>
    /// A rolling array is an array with fixed maximum capacity and in which we can add datas
    /// the real size starts from 0 until reaching maximum capacity while adding elements
    /// further elements are added while removing the oldest element in list
    /// </summary>
    /// <typeparam name="T">
    /// The type of data
    /// </typeparam>
    public interface IRollingArray<T>
    {
        #region Properties

        /// <summary>
        /// Gets the number of elements than can be stored here
        /// </summary>
        int Capacity { get; }

        /// <summary>
        /// Gets the number of elements currently held, in [0;Capacity]
        /// </summary>
        int Count { get; }

        #endregion

        #region Indexers

        /// <summary>
        /// Indexer to access element at a given position
        /// </summary>
        /// <param name="offset">offset of the element to get/set</param>
        /// <returns>the element, or default(T)</returns>
        T this[int offset] { get; set; }

        #endregion

        #region Public Methods

        /// <summary>
        /// Add somme data and check if some element is to be removed (rolling)
        /// </summary>
        /// <param name="data">
        /// data content
        /// </param>
        /// <param name="removed">
        /// true if we reach capacity and the oldest element has to me ejected 
        /// </param>
        /// <returns>
        /// default(T) if removed==false, else the value of removed elemnt
        /// </returns>
        T Add(T data, ref bool removed);

        /// <summary>
        /// Add some data
        /// </summary>
        /// <param name="data">
        /// data content
        /// </param>
        void Add(T data);

        #endregion
    }
}